qx.Class.define("caraffa.forms.Derivaciones",
{
extend : qx.ui.form.ow.FormTab,
construct : function ()
{
	this.base(arguments, "Derivaciones", "Derivaciones");
	
	this._txdDesde = new qx.ui.form.ow.DateText("Desde:");
		this._txdDesde.getLabel().setWidth(50);
		this._txdDesde.getDateText().setWidth(100);
	this._txdHasta = new qx.ui.form.ow.DateText("Hasta:");
		this._txdHasta.getLabel().setWidth(50);
		this._txdHasta.getDateText().setWidth(100);
	this._cmbClinica = new qx.ui.form.ow.ComboBox("Clinica:", [{value:"", label:"TODAS"}, {value:"1", label:"ZIPOLI"}, {value:"2", label:"AVELLANEDA"}]);
		this._cmbClinica.getLabel().setWidth(60);
		this._cmbClinica.getCombo().setWidth(120);
	this._cmbMedico = new qx.ui.form.ow.ComboFilter("Medico:", "", true);
		this._cmbMedico.getLabel().setWidth(60);
	    this._cmbMedico.getCombo().setWidth(250);
	
	this._btnListar = new qx.ui.form.Button("Listar");	
	
	var model = new qx.ui.table.model.Simple();
	model.setColumns(["Medico", "Obra Social", "Practica", "Total"], ["medico", "obra_social", "practica", "total"]);
	
	this._tblDerivados = new qx.ui.table.Table(model);
	this._tblDerivados.setWidth(650);
	this._tblDerivados.setHeight(400);
	
	this._tblDerivados.setColumnWidth(0, 130);
	this._tblDerivados.setColumnWidth(1, 200);
	this._tblDerivados.setColumnWidth(2, 200);
	this._tblDerivados.setColumnWidth(3, 100);
	
	
	this.add(this._txdDesde, {left:70, top:10});
	this.add(this._txdHasta, {left:70, top:40});
	this.add(this._cmbClinica, {left:240, top:10});
	this.add(this._btnListar, {left:450, top:10});
	this.add(this._cmbMedico, {left:240, top:40});
	
	this.add(this._tblDerivados, {left:10, top:70});
	
	var app = this;
	var rpc = new qx.io.remote.Rpc();
	rpc.setTimeout(10000);
	rpc.setUrl(caraffa.Funciones.rpcLocal);
    rpc.setServiceName("turnos");
    rpc.callAsync(function (result, ex, id) {
    	if (ex == null) {
    		for (var i in result) {
				app._cmbMedico.addValue({value:result[i].dni_usuario, label:result[i].apeynom});
			}
    	} else {
    		alert(ex);
    	}
    },"getMedicos");
    
    this._btnListar.addListener("execute", function () {
    	var p = {};
    	p.desde = this._txdDesde.getValueToSQL();
    	p.hasta = this._txdHasta.getValueToSQL();
    	p.clinica = this._cmbClinica.getValue();
    	p.medico = this._cmbMedico.getValue();
    	
    	var app = this;
		var rpc = new qx.io.remote.Rpc();
		rpc.setTimeout(10000);
		rpc.setUrl(caraffa.Funciones.rpcLocal);
        rpc.setServiceName("Derivaciones");
        rpc.callAsync(function (res, ex, id) {
        	if (ex == null) {
        		app._tblDerivados.getTableModel().setDataAsMapArray(res, true, true);
        	} else {
        		alert(ex);
        	}
        },"getDerivaciones", p);
    }, this);
},
members : {
	_txdDesde : null,
	_txdHasta : null,
	_cmbClinica : null
}
});